<?php 
class TopicController extends ApiController {
	
	public function actionList() {
		$c = new CDbCriteria();
		$models = Topic::model()->findAll($c);
		$result = array();
		
		foreach($models as $model) {
			$result[] = $model->attributes;
		}
		$this->_sendSuccess($result);
	}
	
	public function actionGetUserTopics($user_id) {
		$p = Post::model()->tableName();
		$c = new CDbCriteria();
		$c->distinct = true;
		$c->join = "JOIN $p p ON p.topic_id=t.id AND p.user_id={$user_id}";
		$models = Topic::model()->findAll($c);
		$result = array();
		
		foreach($models as $model) {
			$result[] = $model->attributes;
		}
		$this->_sendSuccess($result);
	}
	
}